package com.love.marriage.userFeedbackInfo.service.impl;

import com.love.marriage.userFeedbackInfo.entity.UserFeedbackInfo;
import com.love.marriage.userFeedbackInfo.vo.UserFeedbackInfoPageVo;
import com.love.marriage.userFeedbackInfo.vo.UserFeedbackInfoVo;
import com.love.marriage.userFeedbackInfo.mapper.UserFeedbackInfoMapper;
import com.love.marriage.userFeedbackInfo.service.UserFeedbackInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.love.marriage.utils.UserUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import com.love.marriage.utils.StringUtils;

/**
 * <p>
 * description:  用户问题反馈信息表服务实现类
 * author:       mybatisPlus
 * createDate:   2024-10-16 23:14:35
 * version:      1.0.0
 */
@Service
@RequiredArgsConstructor
public class UserFeedbackInfoServiceImp extends ServiceImpl<UserFeedbackInfoMapper, UserFeedbackInfo> implements UserFeedbackInfoService {

    private final UserFeedbackInfoMapper userFeedbackInfoMapper;

    @Override
    public Page<UserFeedbackInfoPageVo> getPage(Long pageNum, Long pageSize, UserFeedbackInfoVo userFeedbackInfoVo) {
        Page<UserFeedbackInfoVo> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        return userFeedbackInfoMapper.getPage(page, userFeedbackInfoVo);
    }

    @Override
    public UserFeedbackInfoVo queryUserFeedbackInfo(Long id) {
        return userFeedbackInfoMapper.queryUserFeedbackInfo(id);
    }

    @Override
    public UserFeedbackInfoVo addUserFeedbackInfo(UserFeedbackInfoVo userFeedbackInfoVo) {
        UserFeedbackInfo userFeedbackInfo = new UserFeedbackInfo();
        userFeedbackInfoVo.setStatus(1);
        BeanUtils.copyProperties(userFeedbackInfoVo, userFeedbackInfo);
        userFeedbackInfoMapper.insert(userFeedbackInfo);
        UserFeedbackInfoVo res = new UserFeedbackInfoVo();
        BeanUtils.copyProperties(userFeedbackInfo, res);
        return res;
    }

    @Override
    public UserFeedbackInfoVo updateUserFeedbackInfo(UserFeedbackInfoVo userFeedbackInfoVo) {
        UserFeedbackInfo userFeedbackInfo = new UserFeedbackInfo();
        userFeedbackInfoVo.setStatus(3);
        BeanUtils.copyProperties(userFeedbackInfoVo, userFeedbackInfo);
        if (UserUtils.getLoginUser() != null) {
            userFeedbackInfo.setHandlerId(UserUtils.getLoginUser().getId());
        }
        userFeedbackInfoMapper.updateById(userFeedbackInfo);
        return userFeedbackInfoVo;
    }

    @Override
    public Boolean deleteUserFeedbackInfo(String ids) {
        if(StringUtils.isEmpty(ids)) {
            return true;
        }
        List<String> idArr = Arrays.asList(ids.split(","));
        userFeedbackInfoMapper.deleteBatchIds(idArr);
        return true;
    }
}
